<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;

class FriendlinkController extends CommonController
{
    public function index()
    {
		$db = \DB::table("friendlink");
		
		$list = $db->paginate(6);
		
		return view("admin.friendlink.index",['list'=>$list]);
		
    }

    //添加
    public function create()
    {
		
        return view("admin.friendlink.create");	
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //获取要添加的数据
		$data = $request->only("linkname",'linkurl','status','create_at','update_at');
		//执行添加
        $id = \DB::table("friendlink")->insertGetId($data);
        //判断
        if($id>0){
            $info = "友情链接添加成功！";
        }else{
            $info = "友情链接添加失败！";
        }
        
        return view("admin.friendlink.info",['info'=>$info]);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $list = \DB::table("friendlink")->where("id",$id)->get();
		return view("admin.friendlink.edit",["list"=>$list[0]]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
		
        //获取要修改的数据
		$data = $request->only("linkname",'linkurl','status','update_at');
	
		//执行修改
        $id = \DB::table("friendlink")->where("id",$id)->update($data);
        //判断
        if($id>0){
            $info = "友情链接修改成功！";
        }else{
            $info = "友情链接修改失败！";
        }
        
        return view("admin.friendlink.info",['info'=>$info]);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        \DB::table('friendlink')->delete($id);
        return redirect("admin/friendlink");
    }
}
